using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using net_work.Data.Entity.Sys;

namespace net_work.Config.DataBaseConfig.Sys;

public class PersonEntityTypeConfiguration : IEntityTypeConfiguration<Person>
{
    public void Configure(EntityTypeBuilder<Person> builder)
    {
        builder.ToTable("sys_psn");

        builder.HasKey(p => p.Id);

        builder.HasIndex(p => p.PsnIdNum).IsUnique();

        // 配置字段名映射
        builder.Property(p => p.Id).HasColumnName("psn_id");
        builder.Property(p => p.PsnName).HasColumnName("psn_name").IsRequired().HasMaxLength(64);
        builder.Property(p => p.PsnGen).HasColumnName("psn_gen").IsRequired().HasMaxLength(32);
        builder.Property(p => p.PsnIdType).HasColumnName("psn_id_type").IsRequired().HasMaxLength(32);
        builder.Property(p => p.PsnIdNum).HasColumnName("psn_id_num").IsRequired().HasMaxLength(32);
        builder.Property(p => p.PsnBirDate).HasColumnName("psn_bir_date").HasColumnType("date");
        builder.Property(p => p.PsnAddr).HasColumnName("psn_addr").HasMaxLength(256);
        builder.Property(p => p.PsnBirAddr).HasColumnName("psn_bir_addr").HasMaxLength(256);
        builder.Property(p => p.PsnNat).HasColumnName("psn_nat").HasMaxLength(256);
        builder.Property(p => p.PsnRen).HasColumnName("psn_ren").HasMaxLength(256);
        
        builder.Property(p => p.CreatedBy).HasColumnName("create_by").IsRequired().HasMaxLength(64);
        builder.Property(p => p.CreatedTime).HasColumnName("create_time").IsRequired();
        builder.Property(p => p.UpdatedBy).HasColumnName("update_by").IsRequired().HasMaxLength(64);
        builder.Property(p => p.UpdatedTime).HasColumnName("update_time").IsRequired();
        builder.Property(p => p.Remark).HasColumnName("remark").HasMaxLength(256);
        builder.Property(p => p.DelFlag).HasColumnName("del_flag").HasDefaultValue('0');
    }
}